package com.bdqn.BookManage.dao.impl;


import com.bdqn.BookManage.dao.BookTypeDao;
import com.bdqn.BookManage.po.BookType;
import com.bdqn.BookManage.util.DBUtil;

import java.util.List;

/**
 * @author : CP
 * @version: 1.0
 * @program : BookManage
 * @description : 图书类型接口实现类
 * @date : 2020-07-16 16:48
 **/
public class BookTypeDaoImpl implements BookTypeDao {

    /**
     * 查询所有图书类型
     * @return List<BookType>
     */
    @Override
    public List<BookType> queryAll() {
        List<BookType> list = null;
        String sql = "select * from BookType";
        try {
            list = (List<BookType>) DBUtil.queryAll(sql,null,BookType.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    /**
     * 根据类型编号查询图书类型
     * @param id 类型编号
     * @return BookType
     */
    @Override
    public BookType queryById(Integer id) {
        BookType bookType = null;
        String sql = "select * from BookType where typeId=?";
        Object [] obj = {id};
        List<BookType> typeList = (List<BookType>) DBUtil.queryAll(sql, obj, BookType.class);
        bookType = typeList.get(0);
        return bookType;
    }
}
